﻿using UnityEngine;
using System.Collections;

public class Missile : MonoBehaviour {

    float randomX = 0;
    float randomY = 0;


	// Use this for initialization
	void Start () {
        if (transform.position.y >= DataStorage.Instance.GetCenterYOfGame())
        {
            randomX = Random.Range(-0.1f, -1f);
            randomY = Random.Range(-0.1f, -1f);
            float vectorLength = Mathf.Sqrt(randomX * randomX + randomY * randomY);
            randomX = randomX / vectorLength;
            randomY = randomY / vectorLength;
        }
        else
        {
            randomX = Random.Range(0.1f, 1f);
            randomY = Random.Range(0.1f, 1f);
            float unityVector = Mathf.Sqrt(randomX * randomX + randomY * randomY);
            randomX = randomX / unityVector;
            randomY = randomY / unityVector;
        }

	
	}
	
	// Update is called once per frame
	void Update () {
        transform.position += Time.deltaTime * DataStorage.Instance.GetMissileSpeed() * new Vector3(randomX, randomY, 0);
	}

    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.name.Contains("Obstacle") || col.gameObject.name.Contains("Floor"))
        {
            Debug.Log("heyyy");
            Destroy(this.gameObject);
        }
    }
}
